package com.lf.web.service.system.user;

import com.lf.data.Cluster;
import com.lf.data.Page;
import com.lf.data.search.Field;
import com.lf.web.service.ServiceSupport;
import com.lf.web.service.system.group.GroupDAO;
import com.lf.web.service.system.role.Role;
import com.lf.web.service.system.role.RoleDAO;

import java.util.List;

public class UserListService extends ServiceSupport {

    private UserDAO userdao;
    private RoleDAO roledao;
    private GroupDAO groupdao;
    private Cluster users = null;
    private Cluster roles = null;
    private Cluster groups = null;

    public UserListService() {
    }

    public void setUserdao(UserDAO userdao) {
        this.userdao = userdao;
    }

    public void setRoledao(RoleDAO roledao) {
        this.roledao = roledao;
    }

    public String execute() {
        Page page = this.getPage();
        User user = new User();
        form.getCluster(user);
        users = userdao.findPage(user, null, null, page);
        List<Cluster> roleList = roledao.find(null, new Field(Role.NAME), null);
        roles = new Cluster();
        for (Cluster role : roleList) {
            roles.put(role.getId(), role.get(Role.NAME));
        }
        putData();
        return LIST;
    }

    private void putData() {
        context.put("users", users);
        context.put("roles", roles);
    }
}
